/**
 * 安装方法
 *
 * sudo apt-get install fswebcam
 * sudo npm install webcam
 */
require ('./common.js');

var NodeWebcam = require( "node-webcam" );
 
var opts = { 
    width: 1280, 
    height: 720, 
    quality: 100, 
    delay: 0,
    saveShots: true,
    output: "jpeg",
    device: false,
    callbackReturn: "base64", 
    verbose: false 
};

function startCamerashot(playerid) { 
    NodeWebcam.capture( "camera", opts, function( err, data ) { 
        global.camera_img = data;  
        
        var qttstr = {}; //定义消息（可以为字符串，对象等）
        qttstr.camera_img = global.camera_img;    

        global.MqttClient.publish( "super/machine/camera/" + playerid, JSON.stringify(qttstr) );              
    });
}

module.exports = startCamerashot;